<!DOCTYPE html>
<html ng-app="App">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Setaria 分布式统一配置管理</title>

    <!-- Global stylesheets -->
    <link rel="stylesheet" href="assets/css/icons/icomoon/styles.css"/>
    <link rel="stylesheet" href="assets/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="assets/css/core.min.css"/>
    <link rel="stylesheet" href="assets/css/components.min.css"/>
    <link rel="stylesheet" href="assets/css/colors.min.css"/>
    <!-- /global stylesheets -->

    <!-- Core JS files -->
    <script src="assets/js/plugins/loaders/pace.min.js"></script>
    <script src="assets/js/core/libraries/jquery.min.js"></script>
    <!-- /core JS files -->

    <!-- Theme JS files -->
    <script type="text/javascript" src="assets/js/plugins/ui/ripple.min.js"></script>
    <!-- /theme JS files -->

    <!-- Angular JS files -->
    <script src="assets/js/core/libraries/angular.min.js"></script>
    <script src="assets/js/core/libraries/angular-ui-router.min.js"></script>
    <!-- /angular JS files -->

    <!-- Utils JS files -->
    <script src="assets/js/plugins/extensions/store.min.js"></script>
    <!-- /utils JS files -->

    <script>
        var app = angular.module('App', []).controller('LoginCtrl', function ($scope, $http) {
            if (store.get('login.rememberMe')) {
                $scope.rememberMe = store.get('login.rememberMe');
            }

            if ($scope.rememberMe) {
                $scope.email = store.get('login.email');
                $('#password').focus();
            } else {
                $('#email').focus();
            }

            $scope.login = function () {
                if ($scope.rememberMe) {
                    store.set('login.email', $scope.email);
                    store.set('login.rememberMe', $scope.rememberMe);
                } else {
                    store.remove('login.email');
                    store.remove('login.rememberMe');
                }

                var user = {email: $scope.email, password: $scope.password};
                $http.post('r/login', user).success(function (result) {
                    if (result.code >= 300) {
                        alert(result.reasonPhrase);
                        return;
                    }
                    location.href = "index.html";
                });
            }
        });
    </script>
</head>

<body class="login-container" ng-controller="LoginCtrl">

<!-- Main navbar -->
<div class="navbar navbar-inverse bg-indigo">
    <div class="navbar-header">
        <a class="navbar-brand" href="index.html">Setaria 分布式统一配置管理</a>
    </div>
</div>
<!-- /main navbar -->


<!-- Page container -->
<div class="page-container">

    <!-- Page content -->
    <div class="page-content">

        <!-- Main content -->
        <div class="content-wrapper">

            <form ng-submit="login()">
                <div class="panel panel-body login-form">
                    <div class="text-center">
                        <div class="icon-object border-slate-300 text-slate-300"><i class="icon-reading"></i></div>
                        <h5 class="content-group">登录您的管理帐户
                            <small class="display-block">输入认证信息</small>
                        </h5>
                    </div>

                    <div class="form-group has-feedback has-feedback-left">
                        <input type="email" id="email" ng-model="email" class="form-control" placeholder="邮箱"/>

                        <div class="form-control-feedback">
                            <i class="icon-mail5 text-muted"></i>
                        </div>
                    </div>

                    <div class="form-group has-feedback has-feedback-left">
                        <input type="password" id="password" ng-model="password" class="form-control" placeholder="密码"/>

                        <div class="form-control-feedback">
                            <i class="icon-lock2 text-muted"></i>
                        </div>
                    </div>

                    <div class="checkbox">
                        <label>
                            <input type="checkbox" id="rememberMe" ng-model="rememberMe"/> 记住邮箱
                        </label>
                    </div>

                    <div class="form-group">
                        <button type="submit" class="btn bg-primary-400 btn-block">登 录</button>
                    </div>
                </div>
            </form>

        </div>
        <!-- /main content -->

    </div>
    <!-- /page content -->

</div>
<!-- /page container -->

</body>
</html>
